{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exploring the WMS with OWSLib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "surface_flag\n",
      "CRW_SST\n",
      "CRW_BAA\n",
      "CRW_HOTSPOT\n",
      "CRW_DHW\n",
      "CRW_SSTANOMALY\n",
      "CRW_SEAICE\n"
     ]
    }
   ],
   "source": [
    "from owslib.wms import WebMapService\n",
    "\n",
    "\n",
    "url = 'https://pae-paha.pacioos.hawaii.edu/thredds/wms/dhw_5km?service=WMS'\n",
    "\n",
    "web_map_services = WebMapService(url)\n",
    "\n",
    "print('\\n'.join(web_map_services.contents.keys()))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Layer metadata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "layer = 'CRW_SST'\n",
    "wms = web_map_services.contents[layer]\n",
    "\n",
    "name = wms.title\n",
    "\n",
    "lon = (wms.boundingBox[0] + wms.boundingBox[2]) / 2.\n",
    "lat = (wms.boundingBox[1] + wms.boundingBox[3]) / 2.\n",
    "center = lat, lon\n",
    "\n",
    "time_interval = '{0}/{1}'.format(\n",
    "    wms.timepositions[0].strip(),\n",
    "    wms.timepositions[-1].strip()\n",
    ")\n",
    "style = 'boxfill/sst_36'\n",
    "\n",
    "if style not in wms.styles:\n",
    "    style = None"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Single layer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><span style=\"color:#565656\">Make this Notebook Trusted to load map: File -> Trust Notebook</span><iframe src=\"about:blank\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none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gICAgICAgICAgICAgICAgICB1cGRhdGVUaW1lRGltZW5zaW9uOiBmYWxzZSwKICAgICAgICAgICAgICAgICAgICB3bXNWZXJzaW9uOiAiMS4xLjEiLAogICAgICAgICAgICAgICAgfQogICAgICAgICAgICApLmFkZFRvKG1hcF9mNzZlM2VkN2ZkOTQ0M2MyOGVkMWZjYzU3NTBhMDE3Mik7CiAgICAgICAgICAgIAogICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciBsYXllcl9jb250cm9sX2UwMjcyMjgyOTM4NjQzMDVhOGQ3YzY1ZWY3Y2UzY2MxID0gewogICAgICAgICAgICAgICAgYmFzZV9sYXllcnMgOiB7CiAgICAgICAgICAgICAgICAgICAgIm9wZW5zdHJlZXRtYXAiIDogdGlsZV9sYXllcl9iMGQyMDRiZTc2YmI0NjQyOTNiMzJmMjg0NDMwYjczYiwKICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICBvdmVybGF5cyA6ICB7CiAgICAgICAgICAgICAgICAgICAgInNlYV9zdXJmYWNlX3RlbXBlcmF0dXJlIiA6IG1hY3JvX2VsZW1lbnRfZTNjNzNjYzIwYWQwNGNhODgyNTBlNmE5MGQxNGIzZmMsCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICB9OwogICAgICAgICAgICBMLmNvbnRyb2wubGF5ZXJzKAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF9lMDI3MjI4MjkzODY0MzA1YThkN2M2NWVmN2NlM2NjMS5iYXNlX2xheWVycywKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfZTAyNzIyODI5Mzg2NDMwNWE4ZDdjNjVlZjdjZTNjYzEub3ZlcmxheXMsCiAgICAgICAgICAgICAgICB7ImF1dG9aSW5kZXgiOiB0cnVlLCAiY29sbGFwc2VkIjogdHJ1ZSwgInBvc2l0aW9uIjogInRvcHJpZ2h0In0KICAgICAgICAgICAgKS5hZGRUbyhtYXBfZjc2ZTNlZDdmZDk0NDNjMjhlZDFmY2M1NzUwYTAxNzIpOwogICAgICAgIAo8L3NjcmlwdD4= onload=\"this.contentDocument.open();this.contentDocument.write(atob(this.getAttribute('data-html')));this.contentDocument.close();\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x10ccd1fd0>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import folium\n",
    "from folium import plugins\n",
    "\n",
    "lon, lat = -50, -40\n",
    "\n",
    "m = folium.Map(\n",
    "    location=[lat, lon],\n",
    "    zoom_start=5,\n",
    "    control_scale=True\n",
    ")\n",
    "\n",
    "w = folium.raster_layers.WmsTileLayer(\n",
    "    url=url,\n",
    "    name=name,\n",
    "    styles=style,\n",
    "    fmt='image/png',\n",
    "    transparent=True,\n",
    "    layers=layer,\n",
    "    overlay=True,\n",
    "    COLORSCALERANGE='1.2,28',\n",
    ")\n",
    "\n",
    "w.add_to(m)\n",
    "\n",
    "time = plugins.TimestampedWmsTileLayers(\n",
    "    w,\n",
    "    period='PT1H',\n",
    "    time_interval=time_interval\n",
    ")\n",
    "\n",
    "time.add_to(m)\n",
    "\n",
    "folium.LayerControl().add_to(m)\n",
    "\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Multiple layers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><span style=\"color:#565656\">Make this Notebook Trusted to load map: File -> Trust Notebook</span><iframe src=\"about:blank\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" data-html=PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAv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YWQ+Cjxib2R5PiAgICAKICAgIAogICAgICAgICAgICA8ZGl2IGNsYXNzPSJmb2xpdW0tbWFwIiBpZD0ibWFwXzYwNTE4NTQ2OWE4MjQ4YTI5ODJmM2UyMTM3MjA0ZTA0IiA+PC9kaXY+CiAgICAgICAgCjwvYm9keT4KPHNjcmlwdD4gICAgCiAgICAKICAgICAgICAgICAgdmFyIG1hcF82MDUxODU0NjlhODI0OGEyOTgyZjNlMjEzNzIwNGUwNCA9IEwubWFwKAogICAgICAgICAgICAgICAgIm1hcF82MDUxODU0NjlhODI0OGEyOTgyZjNlMjEzNzIwNGUwNCIsCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgY2VudGVyOiBbLTQwLjAsIC01MC4wXSwKICAgICAgICAgICAgICAgICAgICBjcnM6IEwuQ1JTLkVQU0czODU3LAogICAgICAgICAgICAgICAgICAgIHpvb206IDUsCiAgICAgICAgICAgICAgICAgICAgem9vbUNvbnRyb2w6IHRydWUsCiAgICAgICAgICAgICAgICAgICAgcHJlZmVyQ2FudmFzOiBmYWxzZSwKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgKTsKICAgICAgICAgICAgTC5jb250cm9sLnNjYWxlKCkuYWRkVG8obWFwXzYwNTE4NTQ2OWE4MjQ4YTI5ODJmM2UyMTM3MjA0ZTA0KTsKCiAgICAgICAgICAgIAoKICAgICAgICAKICAgIAogICAgICAgICAgICB2YXIgdGlsZV9sYXllcl81NzA0NmE1NWU2YzQ0YmIzYTlmZDhiYjM0ZWE3OWI4YSA9IEwudGlsZUxheWVyKAogICAgICAgICAgICAgICAgImh0dHBzOi8ve3N9LnRpbGUub3BlbnN0cmVldG1hcC5vcmcve3p9L3t4fS97eX0ucG5nIiwKICAgICAgICAgICAgICAgIHsiYXR0cmlidXRpb24iOiAiRGF0YSBieSBcdTAwMjZjb3B5OyBcdTAwM2NhIGhyZWY9XCJodHRwOi8vb3BlbnN0cmVldG1hcC5vcmdcIlx1MDAzZU9w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2UyMTM3MjA0ZTA0LnRpbWVEaW1lbnNpb25Db250cm9sCiAgICAgICAgICAgICk7CgogICAgICAgICAgICAKICAgICAgICAgICAgdmFyIG1hY3JvX2VsZW1lbnRfN2E5NGVlNTRkMmJkNDAyM2EyZDk4MTQwNjYxNDZiMDQgPSBMLnRpbWVEaW1lbnNpb24ubGF5ZXIud21zKAogICAgICAgICAgICAgICAgbWFjcm9fZWxlbWVudF83YTk0ZWU1NGQyYmQ0MDIzYTJkOTgxNDA2NjE0NmIwNCwKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICB1cGRhdGVUaW1lRGltZW5zaW9uOiBmYWxzZSwKICAgICAgICAgICAgICAgICAgICB3bXNWZXJzaW9uOiAiMS4xLjEiLAogICAgICAgICAgICAgICAgfQogICAgICAgICAgICApLmFkZFRvKG1hcF82MDUxODU0NjlhODI0OGEyOTgyZjNlMjEzNzIwNGUwNCk7CiAgICAgICAgICAgIAogICAgICAgICAgICB2YXIgbWFjcm9fZWxlbWVudF8zMWI0NjExM2QzNjM0NWM4OWRmZTJlZDgwNTBkNWIzNyA9IEwudGltZURpbWVuc2lvbi5sYXllci53bXMoCiAgICAgICAgICAgICAgICBtYWNyb19lbGVtZW50XzMxYjQ2MTEzZDM2MzQ1Yzg5ZGZlMmVkODA1MGQ1YjM3LAogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIHVwZGF0ZVRpbWVEaW1lbnNpb246IGZhbHNlLAogICAgICAgICAgICAgICAgICAgIHdtc1ZlcnNpb246ICIxLjEuMSIsCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICkuYWRkVG8obWFwXzYwNTE4NTQ2OWE4MjQ4YTI5ODJmM2UyMTM3MjA0ZTA0KTsKICAgICAgICAgICAgCiAgICAgICAgCiAgICAKICAgICAgICAgICAgdmFyIGxheWVyX2NvbnRyb2xfYWVjNzkyZGNjYzA3NDE4ZjlmM2E2NDgwYzQ0MGNkMDcgPSB7CiAgICAgICAgICAgICAgICBiYXNlX2xheWVycyA6IHsKICAgICAgICAgICAgICAgICAgICAib3BlbnN0cmVldG1hcCIgOiB0aWxlX2xheWVyXzU3MDQ2YTU1ZTZjNDRiYjNhOWZkOGJiMzRlYTc5YjhhLAogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgIG92ZXJsYXlzIDogIHsKICAgICAgICAgICAgICAgICAgICAic2VhX3N1cmZhY2VfdGVtcGVyYXR1cmUiIDogbWFjcm9fZWxlbWVudF83YTk0ZWU1NGQyYmQ0MDIzYTJkOTgxNDA2NjE0NmIwNCwKICAgICAgICAgICAgICAgICAgICAiYW5hbHlzZWQgc2VhIHN1cmZhY2UgdGVtcGVyYXR1cmUgYW5vbWFseSIgOiBtYWNyb19lbGVtZW50XzMxYjQ2MTEzZDM2MzQ1Yzg5ZGZlMmVkODA1MGQ1YjM3LAogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgfTsKICAgICAgICAgICAgTC5jb250cm9sLmxheWVycygKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfYWVjNzkyZGNjYzA3NDE4ZjlmM2E2NDgwYzQ0MGNkMDcuYmFzZV9sYXllcnMsCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sX2FlYzc5MmRjY2MwNzQxOGY5ZjNhNjQ4MGM0NDBjZDA3Lm92ZXJsYXlzLAogICAgICAgICAgICAgICAgeyJhdXRvWkluZGV4IjogdHJ1ZSwgImNvbGxhcHNlZCI6IHRydWUsICJwb3NpdGlvbiI6ICJ0b3ByaWdodCJ9CiAgICAgICAgICAgICkuYWRkVG8obWFwXzYwNTE4NTQ2OWE4MjQ4YTI5ODJmM2UyMTM3MjA0ZTA0KTsKICAgICAgICAKPC9zY3JpcHQ+ onload=\"this.contentDocument.open();this.contentDocument.write(atob(this.getAttribute('data-html')));this.contentDocument.close();\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x119b147b8>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = folium.Map(\n",
    "    location=[lat, lon],\n",
    "    zoom_start=5,\n",
    "    control_scale=True\n",
    ")\n",
    "\n",
    "w0 = folium.raster_layers.WmsTileLayer(\n",
    "    url=url,\n",
    "    name='sea_surface_temperature',\n",
    "    styles=style,\n",
    "    fmt='image/png',\n",
    "    transparent=True,\n",
    "    layers='CRW_SST',\n",
    "    overlay=True,\n",
    ")\n",
    "\n",
    "w1 = folium.raster_layers.WmsTileLayer(\n",
    "    url=url,\n",
    "    name='analysed sea surface temperature anomaly',\n",
    "    styles=style,\n",
    "    fmt='image/png',\n",
    "    transparent=True,\n",
    "    layers='CRW_SSTANOMALY',\n",
    "    overlay=True,\n",
    ")\n",
    "\n",
    "w0.add_to(m)\n",
    "w1.add_to(m)\n",
    "\n",
    "time = folium.plugins.TimestampedWmsTileLayers(\n",
    "    [w0, w1],\n",
    "    period='PT1H',\n",
    "    time_interval=time_interval\n",
    ")\n",
    "\n",
    "time.add_to(m)\n",
    "\n",
    "folium.LayerControl().add_to(m)\n",
    "\n",
    "m"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
